<template>
  <!--  出库申请-->
  <a-card :bordered='false'>
    <!-- 查询区域 -->
    <div class='table-page-search-wrapper'>
      <a-form layout='inline' @keyup.enter.native='search'>
        <a-row :gutter='24'>
          <a-col :xl='6' :lg='7' :md='8' :sm='24'>
            <a-form-item label='订单号'>
              <a-input placeholder='请输入订单号' v-model='queryParams.orderNo' allowClear></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl='6' :lg='7' :md='8' :sm='24'>
            <a-form-item label='状态'>
              <a-select v-model='queryParams.state' placeholder='请选择状态'>
                <a-select-option v-for='(d,i) in stateList' :key='d.id' :value='d.id'>{{ d.value }}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :xl='6' :lg='7' :md='8' :sm='24'>
            <a-form-item label='提交审核时间'>
              <a-range-picker :style="{width: '100%'}" format='YYYY-MM-DD'
                              :placeholder="['开始时间', '结束时间']"
                              v-model='rangePikerDate2'
                              @change='onQueryDateChange2' />
            </a-form-item>
          </a-col>
          <template v-if='toggleSearchStatus'>
            <a-col :xl='6' :lg='7' :md='8' :sm='24'>
              <a-form-item label='业务员'>
                <a-input placeholder='请输入业务员' v-model='queryParams.businessPerson' allowClear></a-input>
              </a-form-item>
            </a-col>
            <a-col :xl='6' :lg='7' :md='8' :sm='24'>
              <a-form-item label='客户'>
                <a-input placeholder='请输入客户名称' v-model='queryParams.user' allowClear></a-input>
              </a-form-item>
            </a-col>
            <a-col :xl='6' :lg='7' :md='8' :sm='24'>
              <a-form-item label='出库时间'>
                <a-range-picker :style="{width: '100%'}" format='YYYY-MM-DD'
                                :placeholder="['开始时间', '结束时间']"
                                v-model='rangePikerDate'
                                @change='onQueryDateChange' />
              </a-form-item>
            </a-col>

            <a-col :xl='6' :lg='7' :md='8' :sm='24'>
              <a-form-item label='来源'>
                <!--              （-1待出库，0已出库，1删除，2撤销）-->
                <!--              <a-input placeholder='请选择状态' v-model='queryParam.state'></a-input>-->
                <a-select v-model='queryParams.source' placeholder='请选择来源'>
                  <a-select-option v-for='(d,i) in sourceList' :key='d.id' :value='d.value'>{{ d.value }}
                  </a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
          </template>
          <a-col :xl='6' :lg='7' :md='8' :sm='24'>
            <span style='float: left;overflow: hidden;' class='table-page-search-submitButtons'>
              <a-button type='primary' @click='search' icon='search'>查询</a-button>
              <a-button type='primary' @click='resetSearch' icon='reload' style='margin-left: 8px'>重置</a-button>
              <a @click='handleToggleSearch' style='margin-left: 8px'>
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'" />
              </a>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class='table-operator'>
      <a-button @click='addModalShow' type='primary' icon='plus'>新增</a-button>
      <a-button type='primary' icon='download' :loading='exportLoading' @click="handleExportXlsAll('出库单')">导出Excel
      </a-button>
      <!--      <a-upload name='file' :showUploadList='false' :multiple='false' :headers='tokenHeader' :action='importExcelUrl'
                      @change='handleImportExcel'>
              <a-button type='primary' icon='import'>导入</a-button>
            </a-upload>-->
      <!--      <a-dropdown v-if='selectedRowKeys.length > 0'>
              <a-menu slot='overlay'>
                <a-menu-item key='1' @click='outOrderBatchDelete(selectedRowKeys)'>
                  <a-icon type='delete' />
                  删除
                </a-menu-item>
              </a-menu>
              <a-button style='margin-left: 8px'> 批量操作
                <a-icon type='down' />
              </a-button>
            </a-dropdown>-->
    </div>

    <!-- table区域-begin -->
    <div>
      <div class='ant-alert ant-alert-info' style='margin-bottom: 16px;'>
        <i class='anticon anticon-info-circle ant-alert-icon'></i> 已选择 <a
        style='font-weight: 600'>{{ selectedRowKeys.length }}</a>项
        <a style='margin-left: 24px' @click='onClearSelected'>清空</a>
      </div>
      <a-table
        ref='table'
        size='middle'
        bordered
        rowKey='id'
        :columns='columns'
        :dataSource='outOrderDataSource'
        :pagination='mainPagination'
        :loading='loading'
        :rowSelection='{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}'
        @change='mainPaginationChange'
        :scroll='{ x: true }'>

        <template slot='htmlSlot' slot-scope='text'>
          <div v-html='text'></div>
        </template>
        <template slot='imgSlot' slot-scope='text'>
          <span v-if='!text' style='font-size: 12px;font-style: italic;'>无图片</span>
          <img v-else :src='getImgView(text)' height='25px' alt=''
               style='max-width:80px;font-size: 12px;font-style: italic;' />
        </template>
        <template slot='fileSlot' slot-scope='text'>
          <span v-if='!text' style='font-size: 12px;font-style: italic;'>无文件</span>
          <a-button
            v-else
            :ghost='true'
            type='primary'
            icon='download'
            size='small'
            @click='uploadFile(text)'>
            下载
          </a-button>
        </template>

        <span slot='action' slot-scope='text, record'>
          <a v-if='record.state==-1' @click='editModalShow(record)' style='margin-right: 5px;'>编辑</a>
          <a v-else @click='editModalShow(record)' style='margin-right: 5px;'>详情</a>


          <a-button style='display: inline-block;margin-left: 10px;'
                    v-if="record.id &&  (record.state===-1 || record.state==='-1'  ) " v-has='"outOrder:saveAndEdit"'
                    type='primary' @click='editModalShow(record)' :loading='firstModalSaveLoading'>提交审核</a-button>

          <a-button style='display: inline-block;margin-left: 10px;'
                    v-if="record.id &&  ( record.state===3 || record.state==='3' ) " v-has='"outOrder:saveAndEdit"'
                    type='' @click='editModalShow(record)' :loading='firstModalSaveLoading'>撤销提交审核</a-button>

          <a-button v-show='record.state==0' style='display: inline-block' type='primary'
                    @click='handleExportXlsOut(record)'>配/提货单</a-button>

          <a-button v-show='record.state==0' style='display: inline-block' type='primary'
                    @click='handleExportXlsAccont(record)'>结算单</a-button>

          <a-button v-show='record.sealNo' style='display: inline-block;color:darkgreen !important;'
                    @click='afterSaleModalShow(record)'>售后单</a-button>


          <a-divider v-if='record.state==-1' type='vertical' />
          <a-dropdown v-if='record.state==-1'>
            <a class='ant-dropdown-link'>更多 <a-icon type='down' /></a>
            <a-menu slot='overlay'>
              <a-menu-item>
                <a-popconfirm v-if='record.state==-1' title='确定删除吗?' @confirm='() => outOrderDelete(record.id)'>
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>

      </a-table>
    </div>

    <!-- 第一个弹窗   <flowerOutorder-modal ref='modalForm' @ok='modalFormOk'></flowerOutorder-modal>-->
    <a-modal v-model:visible='addOrEditVisible' width='97vw' :title='firstModalTitle'
             :maskClosable='false'>
      <a-spin :spinning='firstModalSpinning' tip='数据保存中...'>
        <div>
          <a-row>
            <a-col :span='8'>
              <div style='display: inline-block;width: 100px;'>订单号：</div>
              <div style='display: inline-block;width: 70%'>
                <a-input v-model='outOrder.orderNo' placeholder='自动生成' disabled />
              </div>
            </a-col>
            <a-col :span='8'>
              <div style='display: inline-block;color: red;'>*</div>
              <div style='display: inline-block;width: 100px;'>是否开票：</div>
              <div style='display: inline-block;width: 70%;'>
                <a-radio-group v-model='outOrder.isinvoice' @change='isinvoiceChange' :disabled='disabled.isinvoice'>
                  <a-radio value='是' key='是'>是</a-radio>
                  <a-radio value='否' key='否'>否</a-radio>
                </a-radio-group>
              </div>
            </a-col>
            <a-col :span='8'>
              <div style='display: inline-block;color: red;'>*</div>
              <div style='display: inline-block;width: 100px;'>账期：</div>
              <div style='display: inline-block;'>
                <a-radio-group v-model='outOrder.period' @change='periodChange'
                               :disabled='outOrder.state==0 || outOrder.state==1 || outOrder.state==2'>
                  <a-radio v-for='(item,index) in periodList' :key='index' :value='item'>{{ item }}</a-radio>
                </a-radio-group>
              </div>
            </a-col>

            <a-col :span='8'>
              <a-button-group>
                <div style='display: inline-block;color: red;'>*</div>
                <div style='display: inline-block;width: 100px;'>客户名称：</div>
                <div style='display: inline-block;'>
                  <a-input v-model='outOrder.user' disabled />
                </div>
                <a-button style='display: inline-block;' type='primary' @click='customModalShow'
                          :disabled="disabled.user||outOrder.source==='销售系统'">
                  客户选择
                </a-button>
              </a-button-group>
            </a-col>
            <a-col :span='8'>
              <div style='display: inline-block;color: red;'>*</div>
              <div style='display: inline-block;width: 100px;'>客户电话：</div>
              <div style='display: inline-block;width: 70%'>
                <a-input v-model='outOrder.phone' disabled />
              </div>
            </a-col>
            <a-col :span='8'>
              <div style='display: inline-block;color: red;'>*</div>
              <div style='display: inline-block;width: 100px;'>客户余额：</div>
              <div style='display: inline-block;'>
                <a-input v-model='outOrder.customMoney' disabled />
              </div>
            </a-col>


            <a-col :span='8'>
              <div style='display: inline-block;color: red;'>*</div>
              <div style='display: inline-block;width: 100px;'>收件人：</div>
              <div style='display: inline-block;width: 70%'>
                <a-input v-model='outOrder.touser' :disabled='disabled.businessPerson' />
              </div>
            </a-col>
            <a-col :span='8'>
              <div style='display: inline-block;color: red;'>*</div>
              <div style='display: inline-block;width: 80px;'>收件电话：</div>
              <div style='display: inline-block;width: 70%'>
                <a-input v-model='outOrder.tophone' :disabled='disabled.businessPerson' />
              </div>
            </a-col>
            <a-col :span='8'>
              <div style='display: inline-block;color: red;'>*</div>
              <div style='display: inline-block;width: 80px;'>地址：</div>
              <div style='display: inline-block;width: 70%'>
                <a-input v-model='outOrder.address' :disabled='disabled.businessPerson' />
              </div>
            </a-col>

            <a-col :span='8'>
              <div style='display: inline-block;color: red;'>*</div>
              <div style='display: inline-block;width: 100px;'>业务员：</div>
              <div style='display: inline-block;width: 70%'>
                <a-input v-model='outOrder.businessPerson' placeholder='请输入业务员' :disabled='disabled.businessPerson' />
              </div>
            </a-col>

            <a-col :span='8'>
              <div style='display: inline-block;width: 100px;'>司机：</div>
              <div style='display: inline-block;width: 70%'>
                <a-input v-model='outOrder.carDerver' placeholder='请输入司机' :disabled='disabled.carDerver' />
              </div>
            </a-col>
            <a-col :span='8'>
              <div style='display: inline-block;width: 100px;'>车牌：</div>
              <div style='display: inline-block;width: 70%'>
                <a-input v-model='outOrder.carNo' placeholder='请输入车牌' :disabled='disabled.carNo' />
              </div>
            </a-col>
            <a-col :span='8'>
              <div style='display: inline-block;width: 100px;'>司机电话：</div>
              <div style='display: inline-block;width: 70%'>
                <a-input v-model='outOrder.carPhone' placeholder='请输入司机电话' :disabled='disabled.carPhone' />
              </div>
            </a-col>

            <a-col :span='8'>
              <div style='display: inline-block;color: red;'>*</div>
              <div style='display: inline-block;width: 100px;'>出库人：</div>
              <div style='display: inline-block;width: 70%'>
                <a-input v-model='outOrder.stockOutUser' disabled placeholder='请输入出库人' />
              </div>
            </a-col>
            <a-col :span='8'>
              <div style='display: inline-block;color: red;'>*</div>
              <div style='display: inline-block;width: 100px;'>出库时间：</div>
              <div style='display: inline-block;width: 70%'>
                <a-date-picker v-model:value='outOrder.stockInTime'
                               :default-value="outOrder.stockInTime===null?'':moment(defaultStockInTime, dateFormat)"
                               :valueFormat='dateFormat' placeholder='请选择出库时间'
                               :disabled-date='disabledDate'
                               disabled />
              </div>
            </a-col>

            <a-col :span='8'>
              <div style='display: inline-block;width: 100px;'>总数量：</div>
              <div style='display: inline-block;width: 70%'>
                <a-input v-model='outOrder.number' placeholder='自动生成' disabled />
              </div>
            </a-col>
            <a-col :span='8'>
              <div style='display: inline-block;width: 100px;'>总金额：</div>
              <div style='display: inline-block;width: 70%'>
                <a-input v-model='outOrder.totalprice' placeholder='自动生成' disabled />
              </div>
            </a-col>
          </a-row>

          <a-row style='margin-top: 10px'>
            <a-col :span='24'>
              <div style='display: inline-block;width: 100px;'>备注：</div>
              <div style='display: inline-block;width: 85%'>
                <a-textarea v-model='outOrder.remarks' placeholder='请输入备注' :disabled='disabled.remarks' />
              </div>
            </a-col>
          </a-row>
          <a-row style='margin-top: 10px'>
            <a-col :span='24'>
              <div style='display: inline-block;width: 100px;'>物流信息：</div>
              <div style='display: inline-block;width: 85%'>
                <a-textarea v-model='outOrder.logistics' placeholder='请输入物流信息' :disabled='disabled.logistics' />
              </div>
            </a-col>
          </a-row>
        </div>
        <a-divider />
        <div style='margin-top: -20px'>
          <a-row>
            <a-col>
              <div style='display:inline-block;width: 100%'>
                <div style='font-size: 20px;color: #0742f3;margin-bottom: 3px'><span
                  style='margin-right: 20px;'>销售商品 </span>
                  <a-button v-if='disabled.addButton' style='display: inline-block' type='primary' icon='plus'
                            @click='varietyModalShow'>新增
                  </a-button>
                  <span style='font-size: 14px;color: black;margin-left: 10px'>总价合计：</span><span
                    style='color: red;margin-right: 20px'>{{ allTotalPrice }}</span>
                  <span style='font-size: 14px;color: black;'>数量合计：</span><span style='color: red'>{{ allTotalNum
                    }}</span>
                </div>
                <div style='margin-top: 7px'>
                  <a-table :columns='varietyColumns' :data-source='varietyDataSource'
                           size='small'
                           bordered row-key='uuid'
                           :loading='varietyLoading'
                           :pagination='false'
                           :scroll='{ x: 680,y:300}'>
                    <template v-for="colNumber in ['number']" :slot='colNumber' slot-scope='text, record, index'>
                      <div :key='colNumber' style='width: 100%'>
                        <input v-model:value='record.number' type='number'
                               placeholder='请输入数量'
                               style='width: 100%'
                               @change='numberChange(record,record.number,record.price)'
                               :disabled='disabled.number || !record.storehouse' />
                      </div>
                    </template>
                    <template v-for="colPrice in ['price']" :slot='colPrice' slot-scope='text, record, index'>
                      <div :key='colPrice' style='width: 100%'>
                        <input v-model:value='record.price'
                               placeholder='请输入单价'
                               style='width: 100%'
                               @change='numberChange(record,record.number,record.price)'
                               :disabled='disabled.price || !record.storehouse' />
                      </div>
                    </template>
                    <!--                      <template v-for="colTotalprice in ['totalprice']" :slot='colTotalprice'
                                                    slot-scope='text, record, index'>
                                            <div :key='colTotalprice'>
                                              <a-input v-model:value='record.totalprice'
                                                       placeholder='请输入总价'
                                                       disabled />
                                            </div>
                                          </template>-->
                    <template slot='operation' slot-scope='text, record'>

                      <a-button v-if='!(record.storehouse)&& (outOrder.state===-1)' type='primary'
                                @click='toMuniyOrders(record)'
                                style='margin-right: 5px;'>
                        拆分
                      </a-button>
                      <a-popconfirm v-if='varietyDataSource.length && !disabled.isDelete' title='确定删除?'
                                    @confirm='() => varietyDelete(record.uuid)'>
                        <a>删除</a>
                      </a-popconfirm>

                    </template>
                  </a-table>
                </div>

                <!-- 操作按钮-->
                <div style='margin-top: 5px'>

                  <a-button style='float: right;margin-left: 10px;'
                            v-if="outOrder.state===-1 || outOrder.state==='-1'  " v-has='"outOrder:saveAndEdit"'
                            type='primary' @click='saveOutOrderAddOrEdit' :loading='firstModalSaveLoading'>保存
                  </a-button>
                  <a-button style='float: right;margin-left: 10px;'
                            v-if="outOrder.id &&  (outOrder.state===-1 || outOrder.state==='-1'  ) "
                            v-has='"outOrder:saveAndEdit"'
                            type='primary' @click='toPressDo(outOrder.id)' :loading='firstModalSaveLoading'>提交审核
                  </a-button>
                  <span style='color: red;float: right;'>请先点【保存】后再【提交审核】 </span>
                  <a-button style='float: right;margin-left: 10px;'
                            v-if="outOrder.id &&  ( outOrder.state===3 || outOrder.state==='3' ) "
                            v-has='"outOrder:saveAndEdit"'
                            type='danger' @click='toPressBackDo(outOrder.id)' :loading='firstModalSaveLoading'>撤销提交审核
                  </a-button>
                </div>
              </div>
            </a-col>
            <a-col v-if='outOrder.source!="手动出库"'>
              <div style='display: inline-block;width: 100%;'>
                <div style='font-size: 20px;color: #0742f3;margin-bottom: 3px'>
                  <span style='margin-right: 20px;'>拆分后详情</span>
                  <span style='font-size: 14px;color: black;'>总价合计：</span><span
                  style='color: red;margin-right: 20px'>{{ totalPrice2 }}</span>
                  <span style='font-size: 14px;color: black;'>数量合计：</span><span style='color: red'>{{ totalNum2
                  }}</span>
                </div>
                <div style='margin-top: 10px'>
                  <a-table :columns='varietyColumnsDetail' :data-source='varietyDataSourceDetail'
                           size='small'
                           bordered row-key='uuid'
                           :loading='varietyLoading'
                           :pagination='false'
                           :scroll='{ x: true,y:300}'
                  ></a-table>
                </div>
              </div>
            </a-col>
          </a-row>
        </div>
      </a-spin>
      <template slot='footer'>
        <a-button @click='cancelOutOrderAddOrEdit()'>关闭</a-button>
      </template>
    </a-modal>
    <!--  商品选择的弹窗  -->
    <a-modal v-model:visible='varietyVisible' width='60%' title='商品选择' @ok='varietyAdd'>
      <div style='margin-bottom: 10px;margin-top: -20px'>
        <a-row style='margin-top: 10px'>
          <a-col :span='6'>
            <div style='display: inline-block;width: 45px;'>产品：</div>
            <div style='display: inline-block;width: 70%'>
              <a-input v-model='queryVarietyParams.variety' placeholder='请输入产品名称' allow-clear
                       @change='searchFlowerVarietys' />
            </div>
          </a-col>
          <a-col :span='8'>
            <div style='display: inline-block;width: 80px;'>商品编码：</div>
            <div style='display: inline-block;width: 65%'>
              <a-input v-model='queryVarietyParams.varietyCode' placeholder='请输入商品编码' allow-clear
                       @change='searchFlowerVarietys' />
            </div>
          </a-col>
          <a-col :span='7'>
            <div style='display: inline-block;width: 45px;'>冷库：</div>
            <div style='display: inline-block;width: 70%'>
              <a-select v-model='queryVarietyParams.storehouse' style='width: 100%;' placeholder='请选择冷库'
                        @change='searchFlowerVarietys'>
                <a-select-option v-for='d in hoseList' :key='d.id' :value='d.code'>{{ d.name }}</a-select-option>
              </a-select>
            </div>
          </a-col>
          <a-col :span='3'>
            <a-button type='primary' icon='search' @click='searchFlowerVarietys'>
              查询
            </a-button>
          </a-col>
        </a-row>
      </div>
      <a-table :columns='selectVarietyColumns' :data-source='selectVarietyDataSource' bordered
               :loading='selectVarietyLoading' size='small'
               :row-selection="{selectedRowKeys: selectedRowKeys,type: 'checkbox',onChange:onVarietySelectChange,onSelect:varietyOnSelect,
               onSelectAll:varietyOnSelectAll}"
               row-key='varietyNumber'
               :scroll='{y:280}'
               :pagination='varietyPagination'
               @change='varietyPaginationChange'
      ></a-table>
    </a-modal>

    <!--拆分订单的弹窗-->
    <a-modal v-model:visible='toMuiDialogVisible' width='70%' title='拆分订单' @ok='sureToMuniOrder'>
      <div style='margin-bottom: 2px'>
        <a-row style='margin-top: 0px'>

          <a-col :span='4'>需要出库数量：
            <a>{{ this.orderDetailTotalNumber }}</a>
          </a-col>
          <a-col :span='4'>需要出库总价：
            <a>{{ this.orderDetailTotalPrice }}</a>
          </a-col>
        </a-row>
      </div>
      <a-table :columns='hoseColumns' :data-source='selectedHoseDataSource' bordered
               :loading='hoseLoading'
               :pagination='false'
               row-key='uuid'>

        <template v-for="colstorehouse in ['storehouse']" :slot='colstorehouse' slot-scope='text, record, index'
                  style='width: 100%;'>
          <div :key='colstorehouse' style='float: left;margin-right: 0;width: 100%;'>
            <a-select v-model:value='record.storehouse' style='width: 100%;' placeholder='请选择冷库' disabled>
              <a-select-option v-for='d in hoseList' :key='d.id' :value='d.code'>{{ d.name }}</a-select-option>
            </a-select>
          </div>
        </template>
        <template v-for="colNumber2 in ['number']" :slot='colNumber2' slot-scope='text, record, index'
                  style='width: 100%;'>
          <div :key='colNumber2' style='float: left;margin-right: 0;width: 100%;'>
            <input v-model:value='record.number' style='width: 100%;' placeholder='请输入数量'
                   @change='numberChangeToMui(record)' :disabled='outOrder.state!=1' />
          </div>
        </template>
        <template v-for="totalprice in ['totalprice']" :slot='totalprice' slot-scope='text, record, index'
                  style='width: 100%;'>
          <div :key='totalprice' style='float: left;margin-right: 0;width: 100%;'>
            <input v-model:value='record.totalprice' style='width: 100%;' placeholder='请输入总价'
                   @change='numberChangeToMui(record)' :disabled='outOrder.state!=1' />
          </div>
        </template>
        <template slot='operation' slot-scope='text, record'>
          <a-popconfirm
            v-if='varietyDataSource.length  && ( outOrder.state!=-1 || (outOrder.state==1 && (outOrder.source=="销售系统" || outOrder.source =="补货" )) )'
            title='确定删除?'
            @confirm='() => hoseDelete(record)'>
            <a>删除</a>
          </a-popconfirm>

        </template>

      </a-table>
    </a-modal>
    <!--售后订单的弹窗-->
    <a-modal v-model:visible='afterSaleVisible' width='85%' title='售后单' @ok='suerAfterSale'>
      <div>
        <a-row>
          <a-col :span='12'>
            <div style='display: inline-block;width: 80px;'>销售单号：</div>
            <div style='display: inline-block;width: 70%'>
              <a-input v-model='afterSale.orderNo' placeholder='无数据' disabled />
            </div>
          </a-col>
          <a-col :span='12'>
            <div style='display: inline-block;width: 80px;'>售后单号：</div>
            <div style='display: inline-block;width: 70%'>
              <a-input v-model='afterSale.afOrderNo' placeholder='无数据' disabled />
            </div>
          </a-col>
        </a-row>
        <a-row>
          <a-col :span='12'>
            <div style='display: inline-block;width: 80px;'>货损金额：</div>
            <div style='display: inline-block;width: 70%'>
              <a-input v-model='afterSale.totalPrice' placeholder='无数据' disabled />
            </div>
          </a-col>
          <a-col :span='12'>
            <div style='display: inline-block;width: 80px;'>责任判定：</div>
            <div style='display: inline-block;width: 70%'>
              <a-input v-model='afterSale.responsibility' placeholder='无数据' disabled />
            </div>
          </a-col>
        </a-row>
        <a-row style='margin-top: 10px'>
          <a-col :span='24'>
            <div style='display: inline-block;width: 80px;'>售后理由：</div>
            <div style='display: inline-block;width: 85%'>
              <a-textarea v-model='afterSale.reason' placeholder='无数据' disabled />
            </div>
          </a-col>
        </a-row>
      </div>
      <a-divider />
      <div style='margin-top: -20px'>
        <div style='font-size: 20px;color: #0742f3;margin-bottom: 3px'>售后商品</div>
        <div style='margin-top: 7px'>
          <a-table :columns='afterSaleColumns' :data-source='afterSaleSource'
                   bordered row-key='id'
                   :loading='afterSaleLoading'>
          </a-table>
        </div>
      </div>
    </a-modal>
    <!--    选择客户的弹窗-->
    <a-modal v-model:visible='customVisible' width='70%' title='客户选择' @ok='customAdd'>
      <div style='margin-bottom: 10px'>
        <a-row style='margin-top: 10px'>
          <a-col :span='10'>
            <div style='display: inline-block;width: 90px;'>客户名称：</div>
            <div style='display: inline-block;width: 70%'>
              <a-input v-model='queryCustomParams.name' placeholder='请输入客户名称' allow-clear
                       @change='searchCustom' />
            </div>
          </a-col>
          <a-col :span='10'>
            <div style='display: inline-block;width: 90px;'>客户电话：</div>
            <div style='display: inline-block;width: 70%'>
              <a-input v-model='queryCustomParams.phone' placeholder='请输入客户电话' allow-clear
                       @change='searchCustom' />
            </div>
          </a-col>
          <a-col :span='4'>
            <a-button type='primary' icon='search' @click='searchCustom'>
              查询
            </a-button>
          </a-col>
        </a-row>
      </div>
      <a-table :columns='customColumns' :data-source='customDataSource' bordered
               :loading='customLoading'
               :row-selection="{selectedRowKeys: selectedRowKeys,type: 'radio',onChange:customOnChange}"
               row-key='id'
               :pagination='customPagination'
               :scroll='{y:280}'
               @change='selectCustomPaginationChange'
      ></a-table>
    </a-modal>
  </a-card>
</template>

<script>

import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import FlowerOutorderModal from './modules/FlowerOutorderModal'
import { downFile } from '@/api/manage'
import '@/assets/less/TableExpand.less'
import { ifInteger, ifNumber, ifNumber1 } from '../../utils/ifNumber'
import { getUuid } from '../../utils/uuid'
import { ACCESS_TOKEN } from '@/store/mutation-types'
import {
  getTagBooks, getFlowerOutorderinfo, flowerOutOrderAdd, flowerOutOrderEdit, getFlowerOutorder,
  flowerOutOrderDelete, flowerOutOrderDeleteBatch, flowerOutOrderSureOut, flowerOutOrderToWaitOut,
  flowerOutOrderDList, flowerOutOrderDAdd, flowerOutOrderDDelete, flowerAfSalesMain, getFlowerStorehouse,
  queryFlowerOutOrderInfoListInfo, getFlowerCustom, toPress, toPressBack,
  period, getCustomMoney
} from '../../api/vegetableAPI'
import axios from 'axios'
import moment from 'moment'
import store from '@/store'
import { getCurrentYearAndMonth, getTodayDate, getNowTime } from '@/utils/getDate'
import Vue from 'vue'

export default {
  name: 'FlowerOutorderList',
  mixins: [JeecgListMixin],
  components: {
    FlowerOutorderModal
  },
  data() {
    return {
      queryParams: {// 主页查询
        sourceBase: '',//基地
        sourceGreenhouse: '',//地块
        orderNo: '',//订单号
        state: '',//状态
        source: '',//来源（手动出库、销售系统）
        user: '',//客户
        sDate: '',//开始时间
        eDate: ''//结束时间
      },
      rangePikerDate: [],
      rangePikerDate2: [],
      hoseList: [], //冷库列表
      queryVarietyParams: {// 商品选择弹窗的查询
        sourceBase: '',//基地
        sourceGreenhouse: '',//地块
        variety: '',
        varietyCode: '',
        storehouse: ''
      },
      sourceList: [{ id: '', value: '全部' }, { id: '1', value: '手动出库' }, { id: 2, value: '销售系统' }, {
        id: 3,
        value: '补货'
      }],
      stateList: [{ id: '', value: '全部' }, { id: '-1', value: '草稿' }, { id: '3', value: '待审核' },
        { id: 0, value: '库管确认出库' }, { id: 1, value: '基地负责人审核' }, { id: 2, value: '运管备案' }
      ],
      description: '出库单主表管理页面',
      // 表头
      columns: [
        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          width: 50,
          align: 'center',
          customRender: function(t, r, index) {
            return parseInt(index) + 1
          }
        },
        {
          title: '状态',
          align: 'center',
          dataIndex: 'state',
          customRender: function(text) {
            let stateString = ''
            switch (text) {
              case -1:
                stateString = '草稿'
                break
              case 3:
                stateString = '待审核'
                break
              case 0:
                stateString = '库管确认出库'
                break
              case 1:
                stateString = '基地负责人审核'
                break
              case 2:
                stateString = '运管备案'
                break
              default:
                stateString = ''
            }
            return stateString
          },
          width: 110
        },
        {
          title: '订单号',
          align: 'center',
          dataIndex: 'orderNo',
          width: 150
        },
        {
          title: '销售单号',
          align: 'center',
          dataIndex: 'sealNo',
          width: 150
        }, {
          title: '账期',
          align: 'center',
          width: 100,
          dataIndex: 'period'
        },
        {
          title: '来源',
          align: 'center',
          dataIndex: 'source',
          width: 80
        },
        {
          title: '出库数量',
          align: 'center',
          dataIndex: 'number',
          width: 100
        },

        {
          title: '客户',
          align: 'center',
          dataIndex: 'user',
          width: 100
        },
        {
          title: '联系电话',
          align: 'center',
          dataIndex: 'phone',
          width: 110
        }, {
          title: '业务员',
          align: 'center',
          dataIndex: 'businessPerson',
          width: 70
        }, {
          title: '是否开票',
          align: 'center',
          dataIndex: 'isinvoice',
          width: 50
        }, {
          title: '出库时间',
          align: 'center',
          dataIndex: 'stockInTime',
          width: 100
        }, {
          title: '提交审核时间',
          align: 'center',
          dataIndex: 'topresstime',
          width: 100
        },
        /*{
          title: '地址',
          align: 'center',
          dataIndex: 'address',
          width: 160
        }, */{
          title: '基地负责人',
          align: 'center',
          dataIndex: 'finaSureUser',
          width: 90
        }, {
          title: '基地负责人审核日期',
          align: 'center',
          dataIndex: 'finaSureTime',
          width: 90
        }, {
          title: '运管备案',
          align: 'center',
          dataIndex: 'surepipeuser',
          width: 70
        }, {
          title: '运管备案时间',
          align: 'center',
          dataIndex: 'surepipetime',
          width: 90
        }, {
          title: '库管确认人',
          align: 'center',
          dataIndex: 'sureoutuser',
          width: 70
        }, {
          title: '库管确认时间',
          align: 'center',
          dataIndex: 'sureouttime',
          width: 90
        }, {
          title: '结算确认',
          align: 'center',
          dataIndex: 'accounter',
          width: 70
        }, {
          title: '结算确认时间',
          align: 'center',
          dataIndex: 'accounttime',
          width: 90
        },
        {
          title: '创建日期',
          align: 'center',
          dataIndex: 'createTime',
          width: 140
        },

        {
          title: '创建人',
          align: 'center',
          dataIndex: 'createUser_dictText',
          width: 140
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          scopedSlots: { customRender: 'action' },
          fixed: 'right',
          width: 310
        }
      ],
      url: {
        list: '/flower/flowerOutorder/list',
        delete: '/flower/flowerOutorder/delete',
        deleteBatch: '/flower/flowerOutorder/deleteBatch',
        // exportXlsUrl: '/flower/flowerOutorder/exportXls',
        exportXlsUrl: '/flower/flowerOutorder/exportXlsAll',
        importExcelUrl: 'flower/flowerOutorder/importExcel'
      },
      dictOptions: {},
      outOrderDataSource: [],
      // sourceBaseList: [],//基地列表
      // sourceGreenhouseList: [],//地块列表
      firstModalTitle: '',
      firstModalSpinning: false,//第一个弹窗是否处于加载中
      firstModalSaveLoading: false,//第一个弹窗中的保存按钮是否处于加载中
      addOrEditFlag: 'add',//打开的弹窗是新增还是编辑的标识
      varietyLoading: false,//是否显示第一个弹窗中表格的加载状态
      selectVarietyLoading: true,//是否显示第二个弹窗中表格的加载状态
      addOrEditVisible: false,//是否打开新增或编辑的弹窗
      varietyVisible: false,//是否打开商品选择的弹窗
      outOrder: {
        // sourceBase: '',//基地
        // sourceGreenhouse: '',//地块
        orderNo: '',
        period: '',//账期
        isinvoice: '',
        userid: '',//客户id
        user: '',
        touser: '',
        customMoney: '',//客户余额
        phone: '',
        tophone: '',
        address: '',
        logistics: '',
        carDerver: '',
        source: '',
        carNo: '',
        businessPerson: '',
        stockOutUser: '',
        carPhone: '',
        stockInTime: '',
        remarks: ''
      },
      defaultStockInTime: '',
      dateFormat: 'YYYY-MM-DD',
      varietyColumns: [// 第一个弹窗拆分前表格的表头
        {
          title: '基地',
          align: 'center',
          dataIndex: 'sourceBase_dictText'

        }, {
          title: '大棚',
          align: 'center',
          dataIndex: 'sourceGreenhouse_dictText'

        }, {
          title: '冷库',
          dataIndex: 'storehouse_dictText',
          align: 'center'

        }, {
          title: '成本中心',
          dataIndex: 'cost_dictText',
          align: 'center'

        },
        {
          title: '批次',
          align: 'center',
          dataIndex: 'productionId'
          // width: 120,
        },  {
          title: '产品',
          dataIndex: 'variety',
          align: 'center'

        }, {
          title: '商品编码',
          dataIndex: 'varietyCode',
          align: 'center'

        }, {
          title: '规格',
          dataIndex: 'packingSpecifications',
          align: 'center'

        },
        {
          title: '等级',
          align: 'center',
          dataIndex: 'classes'
        }, {
          title: '单位',
          dataIndex: 'flowerPoleLength',
          align: 'center'

        },
        {
          title: '数量',
          dataIndex: 'number',
          scopedSlots: { customRender: 'number' },
          align: 'center'

        }, {
          title: '单价',
          dataIndex: 'price',

          align: 'center',
          /*customRender: function(text) {
            return parseFloat(text).toFixed(2)
          }*/
          scopedSlots: { customRender: 'price' }
        }, {
          title: '总价',
          dataIndex: 'totalprice',
          //scopedSlots: { customRender: 'totalprice' },
          align: 'center'

        },
        {
          title: '操作',
          dataIndex: 'operation',
          width: 130,
          align: 'center',
          scopedSlots: { customRender: 'operation' },
          fixed: 'right'
        }
      ],
      varietyColumnsDetail: [// 第一个弹窗拆分后表格的表头
        {
          title: '基地',
          align: 'center',
          dataIndex: 'sourceBase_dictText'

        }, {
          title: '大棚',
          align: 'center',
          dataIndex: 'sourceGreenhouse_dictText'

        }, {
          title: '冷库',
          dataIndex: 'storehouse_dictText',
          align: 'center'

        }, {
          title: '产品',
          dataIndex: 'variety',
          align: 'center'

        }, {
          title: '商品编码',
          dataIndex: 'varietyCode',
          align: 'center'

        }, {
          title: '规格',
          dataIndex: 'packingSpecifications',
          align: 'center'

        }, {
          title: '等级',
          align: 'center',
          dataIndex: 'classes'
        }, {
          title: '单位',
          dataIndex: 'flowerPoleLength',
          align: 'center',
          width: 70
        },
        {
          title: '数量',
          dataIndex: 'number',
          scopedSlots: { customRender: 'number' },
          align: 'center'

        }, {
          title: '单价',
          dataIndex: 'price',
          align: 'center',

          customRender: function(text) {
            return parseFloat(text).toFixed(2)
          }
          // scopedSlots: { customRender: 'price' }
        }, {
          title: '总价',
          dataIndex: 'totalprice',
          align: 'center',

          customRender: function(text) {
            if (text === '' || text === null) {
              return text
            } else {
              return parseFloat(text).toFixed(2)
            }
          }
        }
      ],
      selectVarietyColumns: [// 第二个弹窗的表头
       /* {
          title: '基地',
          align: 'center',
          dataIndex: 'sourceBase_dictText'

        }, */{
          title: '地块',
          align: 'center',
          dataIndex: 'sourceGreenhouse_dictText'

        },
        {
          title: '冷库',
          align: 'center',
          dataIndex: 'storehouse_dictText'
        },
        {
          title: '批次',
          align: 'center',
          dataIndex: 'productionId'
          // width: 120,
        },  {
          title: '产品名称',
          align: 'center',
          dataIndex: 'variety'
        }, {
          title: '产品编码',
          align: 'center',
          dataIndex: 'varietyCode'
        }, {
          title: '规格',
          align: 'center',
          dataIndex: 'packingSpecifications'
        }, {
          title: '等级',
          align: 'center',
          dataIndex: 'classes'
        }, {
          title: '单位',
          align: 'center',
          dataIndex: 'flowerPoleLength'
        }, {
          title: '台账库存',
          align: 'center',
          dataIndex: 'number'
        }, {
          title: '占用库存',
          align: 'center',
          dataIndex: 'lockNumber'
        }, {
          title: '可用库存',
          align: 'center',
          dataIndex: 'ableNumber'
        }
      ],
      varietyNumber: 1,
      varietyDataSource: [],// 第一个弹窗中拆分前的商品列表
      varietyDataSourceDetail: [],// 第一个弹窗中拆分后的商品列表
      selectVarietyDataSource: [],// 第二个弹窗中可选择的商品列表
      selectVariety: [],// 第二个弹窗中已选择的商品
      mainPagination: {// 主页表格的分页
        total: 0,
        current: 1,
        pageSize: 10,//每页中显示10条数据
        showSizeChanger: true,
        pageSizeOptions: ['10', '20', '50', '100'],//每页中显示的数据
        showTotal: total => `共有 ${total} 条数据`  //分页中显示总的数据
      },
      varietyPagination: {// 商品选择弹窗中表格的分页
        total: 0,
        current: 1,
        pageSize: 10,//每页中显示10条数据
        showSizeChanger: false,
        showQuickJumper: true,
        showTotal: total => `共有 ${total} 条数据`  //分页中显示总的数据
      },
      disabled: {// 第一个弹窗中各控件是否禁用
        isinvoice: false,
        user: false,
        phone: false,
        address: false,
        logistics: false,
        carDerver: false,
        carNo: false,
        businessPerson: false,
        stockOutUser: false,
        carPhone: false,
        stockInTime: false,
        remarks: false,
        addButton: true,// 第一个弹窗中的新增商品的按钮是否显示
        number: false,// 第一个弹窗中的数量框输入是否禁用
        price: false,// 第一个弹窗中的单价框输入是否禁用
        totalprice: false,// 第一个弹窗中的总价框输入是否禁用

        isToMui: false,
        isDelete: false
      },
      outOrderRecord: {},// 选中编辑的出库单
      outorderInfoFlag: true,//选中编辑的出库单是否已经有商品，true为是，false为否
      mainLoading: false,
      allTotalPrice: 0,//编辑弹窗中所有商品的总价
      allTotalNum: 0,//编辑弹窗中所有商品的总数量
      toMuiDialogVisible: false,//拆分分订单的弹窗显示
      hoseLoading: false,//是否显示拆分弹窗中表格的加载状态

      hoseColumns: [
        {
          title: '基地',
          align: 'center',
          dataIndex: 'sourceBase_dictText',
          width: 120
        }, {
          title: '大棚',
          align: 'center',
          dataIndex: 'sourceGreenhouse_dictText',
          width: 100
        },
        {
          title: '冷库',
          dataIndex: 'storehouse',
          align: 'center',
          width: '100',
          scopedSlots: { customRender: 'storehouse' }
        }, {
          title: '数量',
          dataIndex: 'number',
          align: 'center',
          width: '80',
          scopedSlots: { customRender: 'number' }
        }, {
          title: '单价',
          dataIndex: 'price',
          align: 'center',
          width: '80'
        }, {
          title: '总价',
          dataIndex: 'totalprice',
          align: 'center',
          width: '80',
          scopedSlots: { customRender: 'totalprice' }
        }, {
          title: '库存',
          dataIndex: 'storehouseName',
          align: 'center',
          width: '100'
        }, {
          title: '操作',
          dataIndex: 'operation',
          align: 'center',
          width: 70,
          scopedSlots: { customRender: 'operation' }
        }],//
      orderDetailID: '',//出库单子表的id，用于拆分订单时做主表id
      orderDetailTotalNumber: 0,//出库单子表的出库数量-需要出库的数量
      orderDetailTotalPrice: 0,//出库单子表的出库数量-需要出库的总价

      selectedHoseDataSource: [],//拆分d的数据
      afterSaleVisible: false,
      afterSale: {
        orderNo: '',//销售单号
        afOrderNo: '',//售后单号
        totalPrice: '',//货损金额
        responsibility: '',//责任判定
        reason: ''//售后理由
      },
      afterSaleColumns: [// 售后单弹窗中表格的表头
        {
          title: '产品',
          dataIndex: 'variety',
          align: 'center',
          width: 100
        }, {
          title: '商品编码',
          dataIndex: 'varietyCode',
          align: 'center',
          width: 100
        }, {
          title: '规格',
          dataIndex: 'packingSpecifications',
          align: 'center'
        }, {
          title: '单位',
          align: 'center',
          dataIndex: 'flowerPoleLength'
        }, {
          title: '销售价格',
          dataIndex: 'sealPrice',
          align: 'center'
        }, {
          title: '货损价格',
          dataIndex: 'afSealPrice',
          align: 'center'
        },
        {
          title: '货损数量',
          dataIndex: 'number',
          align: 'center'
        }
      ],
      afterSaleSource: [],
      afterSaleLoading: false,
      totalPrice2: 0,
      totalNum2: 0,
      loginUser: '',
      customVisible: false,//是否打开客户选择的弹窗
      customColumns: [// 客户选择弹窗中表格的表头
        {
          title: '客户id',
          dataIndex: 'id',
          align: 'center',
          width: 120
        }, {
          title: '客户账号',
          dataIndex: 'code',
          align: 'center',
          width: 120
        }, {
          title: '客户名称',
          dataIndex: 'name',
          align: 'center',
          width: 150
        }, {
          title: '客户电话',
          dataIndex: 'phone',
          align: 'center',
          width: 120
        }, {
          title: '客户地址',
          dataIndex: 'address',
          align: 'center'
        }
      ],
      customDataSource: [],//客户列表
      selectCustom: {},//客户选择弹窗中已选择的客户
      customPagination: {// 客户表格的分页
        total: 0,
        current: 1,
        pageSize: 10,//每页中显示10条数据
        showSizeChanger: true,
        pageSizeOptions: ['10', '20', '50', '100'],//每页中显示的数据
        showTotal: total => `共有 ${total} 条数据`  //分页中显示总的数据
      },
      customLoading: false,
      queryCustomParams: {// 客户选择弹窗的查询
        name: '',
        phone: ''
      },
      //出库管理中销售系统推过来的订单在确认出库后调用销售系统修改订单状态的接口的地址
      sellSystemUpdateStatusUrl: '',
      periodList: [],//从后台取回的账期列表（上个账期，当前账期，下个账期）
      exportLoading: false
    }
  },
  computed: {
    importExcelUrl: function() {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    }
  },
  mounted() {
    this.queryFlowerOutorder()
    // this.queryFlowerBase()
  },
  created() {
    //获取冷库列表
    this.hoseList = JSON.parse(localStorage.getItem('ch_storehouse') ? localStorage.getItem('ch_storehouse') : '')
    let loginUserInfo = JSON.parse(localStorage.getItem('pro__Login_Userinfo'))
    this.loginUser = loginUserInfo.value.username
    this.getPeriod()
  },
  methods: {
    moment,
    search() {// 主页中根据条件查询
      if (this.queryParams.source === '全部') {
        this.queryParams.source = ''
      }
      this.mainPagination.current = 1
      this.queryFlowerOutorder()
    },
    onQueryDateChange(date, dateString) {// 日期段选择改变时的回调
      this.queryParams.sDate = dateString[0]
      this.queryParams.eDate = dateString[1]
    },
    onQueryDateChange2(date, dateString) {// 日期段选择改变时的回调
      this.queryParams.topresDate = dateString[0]
      this.queryParams.topreeDate = dateString[1]
    },
    resetSearch() {// 重置查询
      this.queryParams = {// 主页查询
        orderNo: '',//订单号
        state: '',//状态
        source: '',//来源（手动出库、销售系统）
        user: '',//客户
        sDate: '',//开始时间
        eDate: ''//结束时间
      }
      this.rangePikerDate = []
      this.search()
    },
    searchFlowerVarietys() {//根据条件查询商品选择弹窗中的品商品列表
      this.varietyPagination.current = 1
      this.queryFlowerVarietys()
    },
    mainPaginationChange(pagination) {
      this.mainPagination.current = pagination.current
      this.mainPagination.pageSize = pagination.pageSize
      this.queryFlowerOutorder()
    },
    varietyPaginationChange(pagination) {
      /*this.varietyPagination.current = pagination.current
      this.varietyPagination.pageSize = pagination.pageSize*/
      this.varietyPagination = pagination
      this.queryFlowerVarietys()
    },
    queryFlowerOutorder() {// 获取出库单
      this.loading = true
      this.outOrderDataSource.length = 0
      let params = {
        pageNo: this.mainPagination.current,
        pageSize: this.mainPagination.pageSize
      }
      params = { ...this.queryParams, ...params }
      getFlowerOutorder(params).then(res => {
        if (res.success) {
          this.mainPagination.total = res.result.total
          this.outOrderDataSource = res.result.records
        } else {
          this.$message.error(res.message)
        }
        this.loading = false
      })
    },
    addModalShow() {//打开第一个弹窗(新增)
      this.addOrEditFlag = 'add'
      this.firstModalTitle = '新增'
      this.outOrder = {}
      this.outOrderRecord = {}
      let realname = store.getters.userInfo.realname
      let usercode = store.getters.userInfo.username
      this.disabled = {// 各控件是可用，新增按钮可见
        isinvoice: false,
        user: false,
        phone: false,
        address: false,
        logistics: false,
        carDerver: false,
        businessPerson: false,
        carNo: false,
        stockOutUser: false,
        carPhone: false,
        stockInTime: false,
        remarks: false,
        addButton: true,// 第一个弹窗中的新增商品的按钮是否显示
        number: false,// 第一个弹窗中的商品数量框输入是否禁用
        price: false,// 第一个弹窗中的单价框输入是否禁用
        totalprice: false,// 第一个弹窗中的总价框输入是否禁用
        isToMui: false,
        isDelete: false
      }
      this.outOrder = {
        orderNo: '自动生成',
        period: this.periodList.length === 1 ? this.periodList[0] : this.periodList[1],//账期
        isinvoice: '',
        userid: '',//客户id
        user: '',
        touser: '',
        tophone: '',
        customMoney: '',//客户余额
        phone: '',
        address: '',
        logistics: '',
        carDerver: '',
        carNo: '',
        businessPerson: realname,
        stockOutUser: realname,
        carPhone: '',
        stockInTime: '',
        remarks: '',
        state: -1,
        source: '手动出库'
      }
      this.varietyDataSource = []
      this.varietyDataSourceDetail = []
      this.allTotalPrice = 0
      this.allTotalNum = 0
      this.todayDate()
      this.getPeriod()
      this.firstModalSpinning = false
      this.addOrEditVisible = !this.addOrEditVisible
    },
    editModalShow(record) {//打开第一个弹窗(编辑)
      this.outOrderRecord = record
      this.addOrEditFlag = 'edit'
      this.firstModalTitle = '编辑'
      this.outOrder = record
      this.varietyDataSource.length = 0
      this.allTotalPrice = 0
      this.allTotalNum = 0
      this.queryFlowerOutorderinfo(record.id)
      this.queryFlowerOutorderinfoListInfo(record.id)

      if (record.state === 1 || record.state === -1) {
        this.disabled = {
          isinvoice: record.source === '销售系统' && record.state === 1 ? true : false,
          user: false,
          phone: false,
          address: false,
          logistics: false,
          carDerver: false,
          businessPerson: false,
          carNo: false,
          stockOutUser: false,
          carPhone: false,
          stockInTime: false,
          remarks: false,
          addButton: true,
          number: false,
          price: false,
          totalprice: false,
          isToMui: false,
          isDelete: false
        }
      } else {// 否则各控件禁用，新增按钮不可见
        this.disabled = {
          isinvoice: true,
          user: true,
          phone: true,
          address: true,
          logistics: true,
          carDerver: true,
          businessPerson: true,
          carNo: true,
          stockOutUser: true,
          carPhone: true,
          stockInTime: true,
          remarks: true,
          addButton: false,
          number: true,
          price: true,
          totalprice: true,
          isToMui: true,
          isDelete: true
        }
      }
      this.setPeriod()
      this.firstModalSpinning = false
      this.addOrEditVisible = !this.addOrEditVisible
    },
    todayDate() {// 设置新增弹窗中的出库时间的默认值为当前日期
      this.defaultStockInTime = getTodayDate()
      this.outOrder.stockInTime = getTodayDate()
    },
    varietyModalShow() {//打开第二个弹窗
      /*设置下面这两行是为了处理再次打开商品选择弹窗时，
      还会在界面上保留上次选择商品而实际上没有选择任何商品的问题*/
      this.selectedRowKeys.length = 0
      this.selectionRows.length = 0

      this.selectVariety = []
      this.varietyPagination = {// 商品选择弹窗中表格的分页
        total: 0,
        current: 1,
        pageSize: 10,//每页中显示10条数据
        showSizeChanger: false,
        showQuickJumper: true,
        showTotal: total => `共有 ${total} 条数据`  //分页中显示总的数据
      }
      this.varietyNumber = 1
      this.queryVarietyParams = {// 商品选择弹窗的查询
        sourceBase: '',
        sourceGreenhouse: '',
        variety: '',
        varietyCode: '',
        storehouse: ''
      }
      this.queryFlowerVarietys()
      this.varietyVisible = !this.varietyVisible

    },
    queryFlowerOutorderinfo(orderId) {//获取第一个弹窗的拆分前商品数据
      this.varietyLoading = true
      let params = {// 因为第一个弹窗中拆分前的表格会有新增商品的数据，因此无法使用分页，故将pageSize设大一些
        orderId: orderId,
        pageNo: 1,
        pageSize: 1000
      }
      getFlowerOutorderinfo(params).then(res => {
        if (res.success) {
          let records = res.result.records
          if (records.length > 0) {
            this.outorderInfoFlag = true
          } else {
            this.outorderInfoFlag = false
          }

          for (let item of records) {
            this.allTotalPrice += item.totalprice * 10 / 10// 计算总价合计
            this.allTotalNum += item.number * 10 / 10// 计算数量合计
          }
          // 保留两位小数
          this.allTotalPrice = (this.allTotalPrice * 10 / 10).toFixed(2)

          this.varietyDataSource = records
          this.varietyDataSource.map(item => {// 将uuid封装进varietyDataSource中的各用户对象中,为table中的key使用
            item.uuid = getUuid()
          })
        } else {
          this.$message.error(res.message)
        }
        this.varietyLoading = false
      })
    },
    queryFlowerOutorderinfoListInfo(orderId) {//获取第一个弹窗的拆分后商品数据
      this.varietyLoading = true
      let that = this
      let params = {
        mainid: orderId
      }
      queryFlowerOutOrderInfoListInfo(params).then(res => {
        if (res.success) {
          that.totalPrice2 = 0
          that.totalNum2 = 0
          this.varietyDataSourceDetail = res.result.records
          // 将uuid封装进varietyDataSourceDetail中的各用户对象中,为table中的key使用
          this.varietyDataSourceDetail.map(item => {
            item.uuid = getUuid()
            that.totalNum2 += item.number * 10 / 10
            that.totalPrice2 += item.totalprice * 10 / 10
          })
          that.totalPrice2 = (that.totalPrice2 * 10 / 10).toFixed(2)
        } else {
          this.$message.error(res.message)
        }
        this.varietyLoading = false
      })
    },

    queryFlowerVarietys() {// 获取第二个弹窗中的商品列表
      this.selectVarietyLoading = true
      let params = {
        pageNo: this.varietyPagination.current,
        pageSize: this.varietyPagination.pageSize
      }
      params = { ...this.queryVarietyParams, ...params }
      getTagBooks(params).then(res => {
        if (res.success) {
          this.varietyPagination.total = res.result.total
          this.selectVarietyDataSource = res.result.records

          // 将uuid封装进selectVarietyDataSource中的各用户对象中,为table中的key使用
          this.selectVarietyDataSource.map(item => {
            item.uuid = getUuid()
            delete item.id
          })
          // 将varietyNumber封装进selectVarietyDataSource中的各用户对象中,为商品选择弹窗中table的key使用
          if (this.varietyPagination.current > 1) {
            this.varietyNumber = (this.varietyPagination.current - 1) * 10 + 1
          } else {
            this.varietyNumber = 1
          }
          for (let item of this.selectVarietyDataSource) {
            item.varietyNumber = this.varietyNumber
            this.varietyNumber += 1
          }
        } else {
          this.$message.error(res.message)
        }
        this.selectVarietyLoading = false
      })
      /*getFlowerVarietys(params).then(res => {
        if (res.success) {
          this.varietyPagination.total = res.result.total
          this.selectVarietyDataSource = res.result.records

          // 将uuid封装进selectVarietyDataSource中的各用户对象中,为table中的key使用
          this.selectVarietyDataSource.map(item => {
            item.uuid = getUuid()
            delete item.id
          })
          // 将varietyNumber封装进selectVarietyDataSource中的各用户对象中,为商品选择弹窗中table的key使用
          if (this.varietyPagination.current > 1) {
            this.varietyNumber = (this.varietyPagination.current - 1) * 10 + 1
          } else {
            this.varietyNumber = 1
          }
          for (let item of this.selectVarietyDataSource) {
            item.varietyNumber = this.varietyNumber
            this.varietyNumber += 1
          }
        } else {
          this.$message.error(res.message)
        }
        this.selectVarietyLoading = false
      })*/
    },
    onVarietySelectChange(selectedRowKeys, selectionRows) {
      this.selectedRowKeys = selectedRowKeys// 如果不加这两行的话无法单选
      this.selectionRows = selectionRows
    },
    varietyOnSelect(record, selected, selectedRows) {//选择/取消选择某个商品的回调
      if (selected) {//如果是选择某个商品的操作，就将所选择的商品添加进selectVariety
        this.selectVariety.push(record)
      } else {//如果是取消选择某个商品的操作，则从selectVariety中删除相应的商品
        this.selectVariety = this.selectVariety.filter(item => item.varietyNumber !== record.varietyNumber)
      }
    },
    varietyOnSelectAll(selected, selectedRows, changeRows) {//选择/取消选择所有商品的回调
      if (selected) {//如果是选择所有商品的操作，就将所选择的商品添加进selectVariety
        this.selectVariety = [...this.selectVariety, ...changeRows]
      } else {//如果是取消选择所有商品的操作，则从selectVariety中删除相应的商品
        for (let i of changeRows) {
          this.selectVariety = this.selectVariety.filter(item => item.varietyNumber !== i.varietyNumber)
        }
      }
    },
    varietyAdd() {// 第二个弹窗中的新增商品
      /*if (JSON.stringify(this.selectVariety) !== '{}') {//判断this.selectVariety是否为空
        this.selectVariety.number = ''// 为selectVariety对象中添加number元素
        this.selectVariety.totalprice = ''// 为selectVariety对象中添加totalprice元素

        /!*let varietyCodeFlag = false//第一个弹窗表格中的商品是否包含新添加的商品
        for (let item of this.varietyDataSource) {
          if (item.varietyCode === this.selectVariety.varietyCode &&
            item.storehouse_dictText === this.selectVariety.storehouse_dictText) {
            this.$message.error(`该预出库单出库商品中已有冷库为${item.storehouse_dictText}，商品编号为:${item.varietyCode}的商品`)
            varietyCodeFlag = true
            return
          }
        }
        if (!varietyCodeFlag) {
          this.varietyDataSource.push(this.selectVariety)
        }*!/
        this.varietyDataSource.push(this.selectVariety)
      }*/
      this.selectVariety.map(item => {
        item.number = ''
        item.totalprice = ''
      })
      for (let item of this.selectVariety) {
        this.varietyDataSource.push(item)
      }
      this.varietyVisible = !this.varietyVisible
    },
    varietyDelete(id) {// 第一个弹窗中删除商品
      const dataSource = [...this.varietyDataSource]
      this.varietyDataSource = dataSource.filter(item => item.uuid !== id)

      // 计算出合计总价、合计数量
      this.allTotalPrice = 0
      this.allTotalNum = 0
      for (let item of this.varietyDataSource) {
        if (ifNumber1(item.totalprice) && ifNumber1(item.number)) {
          this.allTotalPrice += item.totalprice * 10 / 10
          this.allTotalNum += item.number * 10 / 10
        } else {
          this.allTotalPrice = null
          this.allTotalNum = null
          return
        }
      }
      // 保留两位小数
      this.allTotalPrice = (this.allTotalPrice * 10 / 10).toFixed(2)
    },
    saveOutOrderAddOrEdit() {// 保存新增或编辑出库单
      let allNumberFlag = true//是否所有的商品都有数量的标识
      let allTotalPriceFlag = true//是否所有的商品都有单价的标识
      if (this.outOrder.isinvoice === '' || this.outOrder.isinvoice === null) {
        this.$message.error('请选择是否开票')
      } else if (this.outOrder.period === '' || this.outOrder.period === null) {
        this.$message.error('请选择账期')
      } else if (this.outOrder.user === '' || this.outOrder.user === null) {
        this.$message.error('请选择客户')
      } else if (this.outOrder.touser === '' || this.outOrder.touser === null) {
        this.$message.error('请填写收件人')
      } else if (this.outOrder.tophone === '' || this.outOrder.tophone === null) {
        this.$message.error('请填写收件电话')
      } else if (this.outOrder.address === '' || this.outOrder.address === null) {
        this.$message.error('请填写地址')
      } else if (this.outOrder.phone === '' || this.outOrder.phone === null) {
        this.$message.error('请输入客户电话')
      } /*else if (this.outOrder.logistics === '') {
        this.$message.error('请输入物流信息')
      } */ else if (this.outOrder.stockOutUser === '' || this.outOrder.stockOutUser === null) {
        this.$message.error('请输入出库人')
      } else if (this.outOrder.stockInTime === '' || this.outOrder.stockInTime === null) {
        this.$message.error('请选择出库时间')
      } else if (this.outOrder.businessPerson === '' || this.outOrder.businessPerson === null) {
        this.$message.error('请输入业务员')
      } else {
        for (let item of this.varietyDataSource) {
          if (item.number === '' || item.number === null) {
            this.$message.error('请输入数量')
            allNumberFlag = false
            return
          }
          if (!ifNumber1(item.number)) {
            this.$message.error('数量必须为数字')
            allTotalPriceFlag = false
            return
          }
          if (item.number === 0 || item.number === '0') {
            this.$message.error('数量不能为0')
            allTotalPriceFlag = false
            return
          }

          if (item.price === '' || item.price === null) {
            this.$message.error('请输入单价')
            allTotalPriceFlag = false
            return
          }
          if (!ifNumber1(item.price)) {
            this.$message.error('单价必须为数字')
            allTotalPriceFlag = false
            return
          }
        }
        if (allNumberFlag && allTotalPriceFlag) {
          // 去掉varietyDataSource中每个对象（如果有）的uuid和varietyNumber，此uuid和varietyNumber是在前端生成的
          /*this.varietyDataSource.map(item => {
            delete item.uuid
            delete item.varietyNumber
          })*/
          this.outOrder.flowerOutorderinfoList = this.varietyDataSource// 将商品列表封装近outOrder中
          if (!this.outOrder.source) {
            this.outOrder.source = '手动出库'
          }
          if (this.outOrder.stockInTime.length === 10) {
            this.outOrder.stockInTime = this.outOrder.stockInTime + ' ' + getNowTime()
          }
          if (this.addOrEditFlag === 'add') {// 新增出库单的情况
            if (this.outOrder.flowerOutorderinfoList.length === 0) {
              this.$message.error('至少需要有一个出库商品')
            } else {
              this.firstModalSpinning = true
              this.firstModalSaveLoading = true
              flowerOutOrderAdd(this.outOrder).then(res => {
                if (res.success) {
                  this.queryFlowerOutorder()
                  this.$message.success('保存出库成功')
                  this.addOrEditVisible = false
                } else {
                  this.$message.error(res.message)
                }
                this.firstModalSpinning = false
                this.firstModalSaveLoading = false
              })
            }
          } else {
            if (this.outOrder.flowerOutorderinfoList.length === 0) {
              this.$message.error('至少需要有一个出库商品')
            } else {
              this.firstModalSpinning = true
              this.firstModalSaveLoading = true
              flowerOutOrderEdit(this.outOrder).then(res => {// 编辑出库单的情况
                if (res.success) {
                  this.queryFlowerOutorder()
                  //this.queryFlowerOutorderinfo(this.outOrderRecord.id)
                  this.$message.success('保存成功')
                  this.addOrEditVisible = false
                } else {
                  this.$message.error(res.message)
                }
                this.firstModalSpinning = false
                this.firstModalSaveLoading = false
              })
            }
          }
        }
        this.selectedRowKeys.length = 0//使新增或编辑后不显示批量删除的按钮
      }
    },
    cancelOutOrderAddOrEdit() {
      this.addOrEditVisible = false
    },
    outOrderDelete(id) {
      flowerOutOrderDelete({ id: id }).then(res => {
        if (res.success) {
          this.queryFlowerOutorder()
          this.$message.success('删除成功')
          this.addOrEditVisible = false
        } else {
          this.$message.error(res.message)
        }
      })
    },
    outOrderBatchDelete(selectedRowKeys) {
      if (selectedRowKeys.length > 0) {
        let ids = ''
        for (let item of selectedRowKeys) {
          ids = ids + item + ','
        }
        flowerOutOrderDeleteBatch({ ids: ids }).then(res => {
          if (res.success) {
            this.queryFlowerOutorder()
            this.selectedRowKeys.length = 0
            this.$message.success('批量删除成功')
          } else {
            this.$message.error(res.message)
          }
        })
      }
    },
    sureOut() {// 确认出库，逻辑：先保存然后在调保存编辑的接口中调用确认出库的接口
      let allNumberFlag = true//是否所有的商品都有数量的标识
      let allTotalPriceFlag = true//是否所有的商品都有总价的标识
      if (this.outOrder.isinvoice === '') {
        this.$message.error('请选择是否开票')
      } else if (this.outOrder.period === '' || this.outOrder.period === null) {
        this.$message.error('请选择账期')
      } else if (this.outOrder.user === '') {
        this.$message.error('请选择客户名称')
      } else if (this.outOrder.touser === '') {
        this.$message.error('请选择收件人')
      } else if (this.outOrder.phone === '') {
        this.$message.error('请输入客户电话')
      } /*else if (this.outOrder.logistics === '') {
        this.$message.error('请输入物流信息')
      } */ else if (this.outOrder.stockOutUser === '') {
        this.$message.error('请输入出库人')
      } else if (this.outOrder.stockInTime === '') {
        this.$message.error('请选择出库时间')
      } else if (this.outOrder.businessPerson === '') {
        this.$message.error('请输入业务员')
      } else {
        for (let item of this.varietyDataSource) {
          if (item.number === '' || item.number === null) {
            this.$message.error('请输入数量')
            allNumberFlag = false
            return
          }
          if (!ifNumber1(item.number)) {
            this.$message.error('数量必须为数字')
            allTotalPriceFlag = false
            return
          }
          if (typeof item.number === 'string') {// 如果数量是字符串就将数量转换为数字
            item.number = Number(item.number)
          }
          if (item.price === '' || item.price === null) {
            this.$message.error('请输入单价')
            allTotalPriceFlag = false
            return
          }
          if (!ifNumber1(item.price)) {
            this.$message.error('单价必须为数字')
            allTotalPriceFlag = false
            return
          }
        }

        if (allNumberFlag && allTotalPriceFlag) {
          // 去掉varietyDataSource中每个对象（如果有）的uuid，此uuid是在前端生成的
          this.varietyDataSource.map(item => {
            delete item.uuid
          })
          this.outOrder.flowerOutorderinfoList = this.varietyDataSource// 将商品列表封装进outOrder中
          if (!this.outOrder.source) {
            this.outOrder.source = '手动出库'
          }
          if (this.outOrder.flowerOutorderinfoList.length === 0) {
            this.$message.error('至少需要有一个出库商品')
          } else {
            this.firstModalSpinning = true
            flowerOutOrderEdit(this.outOrder).then(res => {// 先保存出库单数据
              if (res.success) {
                flowerOutOrderSureOut({ id: this.outOrderRecord.id }).then(res => {//再确认出库
                  if (res.success) {
                    if (this.outOrder.source === '销售系统') {
                      // 调用销售系统修改订单状态的接口，通知销售系统该订单已出库
                      let url = this.sellSystemUpdateStatusUrl + '?orderId=' + this.outOrder.sealNo
                      axios.get(url).then(res => {
                        if (res.data.success) {
                          this.$message.success(res.data.message)
                        } else {
                          this.$message.error(res.data.message)
                        }
                      })
                    }
                    this.$message.success('确认出库成功')
                    this.queryFlowerOutorder()
                    this.firstModalSpinning = false
                    this.addOrEditVisible = false
                  } else {
                    this.$message.error(res.message)
                    this.firstModalSpinning = false
                  }
                })
              } else {
                this.$message.error(res.message)
                this.firstModalSpinning = false
                this.addOrEditVisible = false
              }

            })
          }
        }
        this.selectedRowKeys.length = 0//使新增或编辑后不显示批量删除的按钮
      }
    },
    toWaitOut() {// 撤销出库
      this.firstModalSpinning = true
      flowerOutOrderToWaitOut({ id: this.outOrderRecord.id }).then(res => {
        if (res.success) {
          this.queryFlowerOutorder()
          this.$message.success('撤销出库成功')
        } else {
          this.$message.error(res.message)
        }
        this.firstModalSpinning = false
        this.addOrEditVisible = false
      })
    },
    numberChange(record, number, price) {
      if (number && !ifInteger(number)) {
        record.number = 0
        this.$message.error('数量请输入正整数')
        return
      }
      if (price && !ifNumber(price)) {
        record.price = 0
        this.$message.error('单价请输入数字')
        return
      }
      if (ifNumber1(number) && ifNumber1(price) && (number !== null || number !== '') && (price !== null || price !== '')) {
        let totalPrice = (price * 10 / 10) * (number * 10 / 10)
        record.totalprice = totalPrice.toFixed(2)
      } else {
        record.totalprice = null
      }

      // 计算出合计总价、合计数量
      this.allTotalPrice = 0
      this.allTotalNum = 0
      for (let item of this.varietyDataSource) {
        if (ifNumber1(item.totalprice) && ifNumber1(item.number)) {
          this.allTotalPrice += item.totalprice * 10 / 10
          this.allTotalNum += item.number * 10 / 10
        } else {
          this.allTotalPrice = null
          this.allTotalNum = null
          return
        }
      }
      // 保留两位小数
      this.allTotalPrice = (this.allTotalPrice * 10 / 10).toFixed(2)
    },
    //拆分订单按钮
    toMuniyOrders(record) {
      this.toMuiDialogVisible = true

      this.hoseLoading = true
      this.orderDetailID = record.id
      this.orderDetailTotalNumber = record.number
      this.orderDetailTotalPrice = record.totalprice
      if (this.orderDetailTotalNumber == 0) {
        this.$message.error('出库数量为0，请重新填写后才能拆分')
        return
      }
      if (this.orderDetailTotalPrice * 10 / 10 <= 0) {
        this.$message.error('出库总价 小于等于0，请重新填写后才能拆分')
        return
      }
      //this.initFlowerStorehouse(record) //查询冷库数据

      //查询数据 list
      flowerOutOrderDList({ 'mainid': record.id }).then((res) => {
        if (res.success) {
          this.selectedHoseDataSource = res.result.records
          this.selectedHoseDataSource.map(item => {//添加uuid进selectedHoseDataSource里的每个对象中，此uuid是为table中的key使用的
            item.uuid = getUuid()
          })
        } else {
          this.$message.error(res.message)
        }
        this.hoseLoading = false
      })

    },
    //拆分订单确认按钮
    sureToMuniOrder() {
      let that = this
      let sumnumber = 0
      let sumprice = 0
      for (let i = 0; i < this.selectedHoseDataSource.length; i++) {
        sumnumber += this.selectedHoseDataSource[i].number * 10 / 10 + 0
        sumprice += this.selectedHoseDataSource[i].totalprice * 10 / 10 + 0
      }
      if (sumprice != this.orderDetailTotalPrice) {
        that.$message.error('合计总价(' + sumprice + ')不等于出库单子表的总价（' + this.orderDetailTotalPrice + ')')
        return
      }
      if (sumnumber * 10 / 10 < this.orderDetailTotalNumber * 10 / 10) {
        that.$confirm({
          title: '提示',
          content: '各冷库的合计小于( ' + sumnumber + ' )需要出库的数量( ' + that.orderDetailTotalNumber + ' )，是否确定？?',
          onOk: function() {
            if (!that.disabled.isToMui) {
              that.selectedHoseDataSource.map(item => {// 去掉selectedHoseDataSource中每个对象的uuid，此uuid是在前端生成的
                delete item.uuid
              })
              that.hoseLoading = true
              //调用接口保存数据  add2
              flowerOutOrderDAdd(that.selectedHoseDataSource).then((res) => {
                if (res.success) {
                  that.$message.info('保存成功')
                  that.toMuiDialogVisible = false
                  that.queryFlowerOutorderinfoListInfo(that.outOrderRecord.id)
                } else {
                  that.$message.error(res.message)
                }
                that.hoseLoading = false
              })
            } else {
              that.toMuiDialogVisible = false
            }
          }
        })
      } else {
        if (!that.disabled.isToMui) {
          that.selectedHoseDataSource.map(item => {// 去掉selectedHoseDataSource中每个对象的uuid，此uuid是在前端生成的
            delete item.uuid
          })
          that.hoseLoading = true
          //调用接口保存数据  add2
          flowerOutOrderDAdd(that.selectedHoseDataSource).then((res) => {
            if (res.success) {
              that.$message.info('保存成功')
              that.toMuiDialogVisible = false
              that.queryFlowerOutorderinfoListInfo(that.outOrderRecord.id)
            } else {
              that.$message.error(res.message)
            }
            that.hoseLoading = false
          })
        } else {
          that.toMuiDialogVisible = false
        }
      }
    },
    //数量改变
    numberChangeToMui(record) {
      if ((this.orderDetailTotalNumber * 10 / 10) <= 0) {
        this.$message.error('出库数量为小于等于0，请重新填写后才能拆分')
        return
      }
      if ((this.orderDetailTotalPrice * 10 / 10) <= 0) {
        this.$message.error('出库总价 小于等于0，请重新填写后才能拆分')
        return
      }
      let sumnumber = 0
      let sumToalprice = 0
      for (let i = 0; i < this.selectedHoseDataSource.length; i++) {
        sumnumber += (this.selectedHoseDataSource[i].number * 10 / 10 + 0)
        sumToalprice += (this.selectedHoseDataSource[i].totalprice * 10 / 10 + 0)
      }
      if ((sumnumber * 10 / 10) > (this.orderDetailTotalNumber * 10 / 10)) {
        this.$message.error('各冷库的合计不能超过需要出库的数量' + this.orderDetailTotalNumber)
        record.number = 0
        return
      }
      if ((sumToalprice * 10 / 10) > (this.orderDetailTotalPrice * 10 / 10)) {
        this.$message.error('各冷库的合计不能超过需要出库的总价' + this.orderDetailTotalPrice)
        record.totalprice = 0
        return
      }
      if (!record.storehouseName) {
        record.storehouseName = 0
      }
      if ((record.number * 10 / 10) > (record.storehouseName * 10 / 10)) {
        this.$message.error('填写数量不能超过库存数量' + record.storehouseName)
        record.number = 0
        return
      }
      if (record.totalprice && record.number != 0 && record.number != '0') {
        let price = ((record.totalprice * 10 / 10) / (record.number * 10 / 10))
        record.price = price.toFixed(2)
      }

    },
    //拆分的删除
    hoseDelete(record) {
      this.selectedHoseDataSource.splice(this.selectedHoseDataSource.indexOf(record), 1)
    },
    afterSaleModalShow(record) {// 打开售后订单的modal
      this.afterSale = {
        orderNo: '',//销售单号
        afOrderNo: '',//售后单号
        totalPrice: '',//货损金额
        responsibility: '',//责任判定
        reason: ''//售后理由
      }
      this.afterSaleSource = []
      this.queryFlowerAfSalesMain(record.sealNo)
      this.afterSaleVisible = !this.afterSaleVisible
    },
    queryFlowerAfSalesMain(sealNo) {// 查询售后单，sealNo为销售单号
      let params = {
        orderNo: sealNo
      }
      flowerAfSalesMain(params).then(res => {
        if (res.success) {
          this.afterSale = res.result
          this.afterSaleSource = res.result.flowerAfSalesDetalList
        } else {
          this.$message.error(res.message)
        }
      })
    },
    suerAfterSale() {//售后单弹窗的确定按钮
      this.afterSaleVisible = false
    },
    handleExportXlsAll() {
      let fileName = '出库单(全部)'
      let param = this.queryParams
      this.exportLoading = true

      if (this.selectedRowKeys && this.selectedRowKeys.length > 0) {
        param['selections'] = this.selectedRowKeys.join(',')
      }
      let urlss = '/flower/flowerOutorder/exportXlsAll'
      downFile(urlss, param).then((data) => {
        if (!data) {
          this.$message.warning('文件下载失败')
          return
        }
        if (typeof window.navigator.msSaveBlob !== 'undefined') {
          window.navigator.msSaveBlob(new Blob([data], { type: 'application/vnd.ms-excel' }), fileName + '.xlsx')
          this.exportLoading = false
        } else {
          let url = window.URL.createObjectURL(new Blob([data], { type: 'application/vnd.ms-excel' }))
          let link = document.createElement('a')
          link.style.display = 'none'
          link.href = url
          link.setAttribute('download', fileName + '.xlsx')
          document.body.appendChild(link)
          link.click()
          document.body.removeChild(link) //下载完成移除元素
          window.URL.revokeObjectURL(url) //释放掉blob对象
          this.exportLoading = false
        }
      })
    },
    handleExportXlsAccont(record) {
      let fileName = '结算单' + record.orderNo
      let param = this.getQueryParams()
      if (this.selectedRowKeys && this.selectedRowKeys.length > 0) {
        param['selections'] = this.selectedRowKeys.join(',')
      }
      let urlss = '/flower/flowerOutorder/exportXlsForAccont'
      downFile(urlss, record).then((data) => {
        if (!data) {
          this.$message.warning('文件下载失败')
          return
        }
        if (typeof window.navigator.msSaveBlob !== 'undefined') {
          window.navigator.msSaveBlob(new Blob([data], { type: 'application/vnd.ms-excel' }), fileName + '.xlsx')
        } else {
          let url = window.URL.createObjectURL(new Blob([data], { type: 'application/vnd.ms-excel' }))
          let link = document.createElement('a')
          link.style.display = 'none'
          link.href = url
          link.setAttribute('download', fileName + '.xlsx')
          document.body.appendChild(link)
          link.click()
          document.body.removeChild(link) //下载完成移除元素
          window.URL.revokeObjectURL(url) //释放掉blob对象
        }
      })
    },
    //是否开票的change
    isinvoiceChange(e) {
      this.outOrder.isinvoice = e.target.value
    },
    customModalShow() {//打开客户选择弹窗
      /*设置下面这两行是为了处理再次打开客户选择弹窗时，
      还会在界面上保留上次选择客户而实际上没有选择任何客户的问题*/
      this.selectedRowKeys.length = 0
      this.selectionRows.length = 0

      this.customPagination = {// 客户表格的分页
        total: 0,
        current: 1,
        pageSize: 10,//每页中显示10条数据
        showSizeChanger: true,
        pageSizeOptions: ['10', '20', '50', '100'],//每页中显示的数据
        showTotal: total => `共有 ${total} 条数据`  //分页中显示总的数据
      }
      this.queryCustomParams = {// 客户选择弹窗的查询
        name: '',
        phone: ''
      },
        this.customVisible = true
      this.queryFlowerCustom()
    },
    //获取客户列表
    queryFlowerCustom() {
      this.customLoading = true
      let params = {
        pageNo: this.customPagination.current,
        pageSize: this.customLoading.pageSize
      }
      params = { ...this.queryCustomParams, ...params }
      getFlowerCustom(params).then(res => {
        if (res.success) {
          this.customPagination.total = res.result.total
          this.customDataSource = res.result.records
        } else {
          this.$message.error(res.message)
        }
        this.customLoading = false
      })
    },
    customOnChange(selectedRowKeys, selectionRows) {//选择客户弹窗中选择客户时的回调
      this.selectedRowKeys = selectedRowKeys// 如果不加这两行的话无法多选
      this.selectionRows = selectionRows

      this.selectCustom = selectionRows[0]
      this.queryCustomMoney(this.selectCustom.id)
    },
    queryCustomMoney(userId) {//查询客户余额
      getCustomMoney({ 'userId': userId }).then(res => {
        if (res.success) {
          this.outOrder.customMoney = res.result
        } else {
          this.$message.error('获取客户余额失败')
        }
      })
    },
    selectCustomPaginationChange(pagination) {
      this.customPagination = pagination
      this.queryFlowerCustom()
    },
    customAdd() {// 客户选择中的确定选择客户
      if (JSON.stringify(this.selectCustom) !== '{}') {
        this.outOrder.userid = this.selectCustom.id
        this.outOrder.user = this.selectCustom.name
        this.outOrder.touser = this.selectCustom.name //收件人默认等于客户
        this.outOrder.phone = this.selectCustom.phone
        this.outOrder.tophone = this.selectCustom.phone//收件电话默认客户电话
        this.outOrder.address = this.selectCustom.address
      }
      this.customVisible = false
    },
    searchCustom() {// 客户选择弹窗中的查询客户
      this.queryFlowerCustom()
    },
    // 日期选择框中不可选择的日期
    disabledDate(current) {
      return current < moment().subtract(1, 'day')//当前日期以前不可用
    },
    getPeriod() {
      period().then(res => {
        this.periodList = res
      })
    },
    //账期单选的change
    periodChange(e) {
      this.outOrder.period = e.target.value
    },
    //设置账期（打开编辑弹窗时用）
    setPeriod() {
      period().then(res => {
        this.periodList = res
        if (this.periodList.length === 1) {//账期开关关闭时
          this.periodList.push(this.outOrder.period)
          this.periodList = Array.from(new Set(this.periodList))//去重
          this.periodList.sort()//升序排序
        }
      })
    },
    handleExportXlsOut(record) {
      const token = Vue.ls.get(ACCESS_TOKEN)
      let url = window._CONFIG['jimuURL'] + '/jmreport/shareView/748391289810227200?id=' + record.id + '&token=' + token
      // let url =  "http://scht.ythxdny.com:9998/jmreport/shareView/748391289810227200?id="+record.id+"&token="+token
      window.open(url)
    },
    toPressDo(id) {
      this.firstModalSaveLoading = true
      this.firstModalSpinning = true
      toPress({ 'id': id }).then(res => {
        if (res.success) {
          this.$message.success(res.message)
          this.addOrEditVisible = false
          this.queryFlowerOutorder()
        } else {
          this.$message.error(res.message)
        }
        this.firstModalSaveLoading = false
        this.addOrEditVisible = false
        this.firstModalSpinning = false
      })
    },
    toPressBackDo(id) {
      this.firstModalSaveLoading = true
      this.firstModalSpinning = true
      toPressBack({ 'id': id }).then(res => {
        if (res.success) {
          this.$message.success(res.message)
          this.addOrEditVisible = false
          this.queryFlowerOutorder()
        } else {
          this.$message.error(res.message)
        }
        this.firstModalSaveLoading = false
        this.firstModalSpinning = false
      })
    }
    // handleExportXlsOut(record) {
    //   let fileName = '出库单' + record.orderNo
    //   let param = this.getQueryParams()
    //   if (this.selectedRowKeys && this.selectedRowKeys.length > 0) {
    //     param['selections'] = this.selectedRowKeys.join(',')
    //   }
    //   let urlss = '/flower/flowerOutorder/exportXlsForOut'
    //   downFile(urlss, record).then((data) => {
    //     if (!data) {
    //       this.$message.warning('文件下载失败')
    //       return
    //     }
    //     if (typeof window.navigator.msSaveBlob !== 'undefined') {
    //       window.navigator.msSaveBlob(new Blob([data], { type: 'application/vnd.ms-excel' }), fileName + '.xlsx')
    //     } else {
    //       let url = window.URL.createObjectURL(new Blob([data], { type: 'application/vnd.ms-excel' }))
    //       let link = document.createElement('a')
    //       link.style.display = 'none'
    //       link.href = url
    //       link.setAttribute('download', fileName + '.xlsx')
    //       document.body.appendChild(link)
    //       link.click()
    //       document.body.removeChild(link) //下载完成移除元素
    //       window.URL.revokeObjectURL(url) //释放掉blob对象
    //     }
    //   })
    // },
  }
}
</script>
<style scoped>
@import '~@assets/less/common.less';

.editable-cell {
  position: relative;
  background-color: #0c8fcf;
}

.ant-col-6, .ant-col-7, .ant-col-8, .ant-col-12 {
  /*margin-top: 3px;*/
  height: 40px;
}

</style>
